/**
 * @param {number[]} prices
 * @param {number} money
 * @return {number}
 */
var buyChoco = function (prices, money) {
    let arr = prices.filter(item=>{
        return item<money
    })
    if(arr.length == 0) return money;
    let num = money
    arr.forEach(item=>{
        arr.forEach(val=>{
            if(val+item < num){
                num = val+item
            }
        })
    })
    return num
};
console.log(buyChoco([1,2,2],3));
console.log(buyChoco([3,2,3],3));

